var imageIDs = []; // this contains all image id, is is the image url
var series = []; // contain the series information
var seriesArray = []; // contain series and instances information
var tags = [];
var tagArray = []; // contain instances tags
var loaded = []; // Is the image loaded
var multiSeries = []; // is multi series
var loadedIndex = []; // Indicate each window loaded series
var clickedSeries = -1;
var rangeMin = 0; // for input range
var rangeMax = 0;
var reportFlag = '';
var sort = 0; // when there is 1 viewport (viewportNum == 0), "sort" describes the chosen series index
var image2askid = '';
var iWindowVNum = 1;
var iWindowHNum = 1;
var patId = 0;
var studyUID = 0;
var imageType = "";
var totalSeries = 0;
var isMobile = $.browser.mobile;
var isDesktop = $.browser.desktop;
var askId = '';  // 咨询ID
var imageId = '';
var imageInfo = null;
var studyNumber = 0; // Total studyNumber in this ask
var groupIndex = [];
var iSeriesNum = 0;  // total series number
var locations = [];  // each series location
var thickness = [];  // each series thickness
var groupNum = 0; // the number of the groups, in each of which the series are synchronizers
var orientation = []; // each series orientation
var position = []; //
var firwidth = 0;
var changgeSeriesByIndex = -1;
var synchronizers = [];
var synchrSwitch = true; // to judge whether the "synchronizer" button has been pressed
var viewportNum = 0; // total viewport number
var dis = true;
var curImageNum = 0;
var maxSeriesNum = 0; // the maximum of "numberOfInstances" in every series
var wheelInstanceNum = []; // used to display the current instance number according to mouse wheel
var elementChoosed = ''; // current element in canvas which is clicked
var initialWW = []; // initial window width of every instance
var initialWL = []; // initial window level of every instance
var globalWW = []; // when the window width of every window is modified, it is saved in "globalWW"
var globalWL = []; // when the window center of every window is modified, it is saved in "globalWL"
var imageScale = []; // the current scale of each image in every window
var contrastButtonPressed = false; // to judge whether the "enableWindowLevelTool" button has been pressed
var referenceLineButtonPressed = false; // to judge whether the "referenceLine" button has been pressed
var getDicomButtonPressed = false; // to judge whether the "getDicom" button has been pressed
var cardFlag = false; // 用于病例的显示
var askDoctorId = 0;
var imageReportName = '';
var imageReportSex = '';
var imageReportAge = '';
var askFlag = false; // 用于阅片页面发起咨询选择专家时通过查询条件查询的判断标识
var report = null;  // Used for report.
var isSReport = '';

var autoPlayButtonPressed = true;
var isFirst = true;//用于左侧框收缩时判断是否为第一次
var windowWidth = document.body.clientWidth;//dom的宽度
var windowHeight = document.body.clientHeight;//dom高度
var isGetDicomButtonPressed = false;//判断是不是按的getDicom

//Get configuration parameters
// hosturl =lm.address.imageCloud_8888_noCloud;
hosturl =lm.environment().imageCloudPort;




$(function () {
    $('#liViewer').css('marginLeft',(($('.tabs-container').width()-$('#toolbar-function').width())/2 + 15).toString() + 'px');//设置工具栏的位置
    // Dynamically distinguish if javascript code for mobile should
    // be loaded.
    if (isMobile) {
        var oHead = document.getElementsByTagName('HEAD').item(0);
        var oScript = document.createElement("script");
        oScript.type = "text/javascript";
        oScript.src = '/imagecloud/js/touch-emulator.js';
        oHead.appendChild(oScript);
        $('#').hide();
    }

    // on the mobile screen, the two buttons can help you browse current series
    // slice by slice ------------------------------------------------- Updated by TanQilu
    if (isMobile) {
        $('#pageUp').click(function (e) {
            var index = parseInt(curImageNum, 10);
            index = index - 1;
            index = index > -1 ? index : 0;

            //         if(contrastButtonPressed && navigator.userAgent.indexOf('iPhone' ) == -1){
            readjustInstanceWWWL(index, $('#image00').get(0));
            //        } else {
            //              selectNewImage(index);
            //        }

        });

        $('#pageDown').click(function (e) {
            var index = parseInt(curImageNum, 10);
            index = index + 1;
            index = index < seriesArray[sort].instance.length ? index : seriesArray[sort].instance.length - 1;

            //         if(contrastButtonPressed && navigator.userAgent.indexOf('iPhone' ) == -1){
            readjustInstanceWWWL(index, $('#image00').get(0));
            //        } else {
            //              selectNewImage(index);
            //        }
        });
    }

    // Configure the notification
    notifyConfigure();

    // $.ajax({
    //     url : hosturl + '/imagecloud/service/ask/imagelist?askid=' + askid + '&curpage=1&pagesize=1000' ,
    //     type : 'get',
    //     dataType : 'jsonp',
    //     success : function(data) {
    //             console.log(data)
    //         }
    //     })



    // var service_share2image_shareid_data = {
    //     shareid:'105'
    // };
    // lmViewer.srv.service_share2image_shareid(service_share2image_shareid_data,function(data){
    //     console.log("[tabViewer|service_share2image_shareid|success]---"+JSON.stringify(data,null,4));
    // },fail());




    lmViewer.srv.service_ImageViewer_getConfig(function(data){
        console.log("[tabViewer|service_ImageViewer_getConfig|success]---"+JSON.stringify(data,null,4));
        var urls = data.message.split(";");

        // load image
        dcmurl = urls[0];
        serverURL = urls[1];
        queryString = window.location.href;
        patId = getParameter(queryString, "patientID");
        studyUID = getParameter(queryString, "studyUID");
        imageType = getParameter(queryString, "type");
        reportFlag = getParameter(queryString, "reportFlag");
        image2askid = getParameter(queryString, "image2askid" );
        isSReport = getParameter(queryString, "sReport" );

        //zssure,at LinkingMed 2016-07-07
        if(patId == null||patId=="" || studyUID==null ||studyUID==""||imageType==null ||imageType=="")
        {
            patId = (patId == null||patId=="")?getParameter(queryString, "patientID"):patId;
            studyUID = (studyUID==null ||studyUID=="")?window.localStorage.getItem('studyUID'):studyUID;
            imageType = (imageType==null ||imageType=="")?getParameter(queryString, "type"):imageType;
        }
        //zssure,at LinkingMed 2016-07-07 end
        // get the dicom tags
        loadTagInfos(hosturl, studyUID);

        // 判断是否显示相关的Tab
        if (null == image2askid || '' == image2askid || 'null' == image2askid) {
            //表示是阅片的状态
            $("#liTabReport").css("display", "none");
            $("#liTabInfo").css("display", "none");
            $("#liTabSReport").css("display", "none");
        }
        else {
            //表示是咨询的状态
            $("#liTabStartConsult").css("display", "none");
        }
        // if(askid){
        //
        // }
        // askId = window.localStorage.getItem('askid');
        // imageId = window.localStorage.getItem('imageid');
        askId = getParameter(queryString, "askid" );
        imageId = getParameter(queryString, "imageid" );

        totalSeries = 0;
        if (isDesktop === true) {
            $('#enableScrollStack').css('display', 'none');
        }
        cancelBindKey();
        loadButtonHint();
        getStudyNumber();

        var params = {
            imageId:imageId
        }
        lmViewer.srv.service_image_imageId(params,function(data){
            console.log("[tabViewer|service_image_imageId|success]---"+JSON.stringify(data,null,4));
            var message = data.message;
            imageInfo = message;

            iWindowVNum = 1;
            iWindowHNum = 1;
            loadStudy(hosturl, patId, studyUID, dcmurl, serverURL);
            window.addEventListener('resize', resizeCanvas, false);
            if (imageType == 'jpg') {
                $('#getDicom').find('span').html('DCM');
            } else {
                $('#getDicom').find('span').html('JPG');
            }
        },function(data){
            humane.log("影像服务器连接错误，请联系客服。", {
                timeout: 4000,
                clickToClose: true,
                addnCls: 'humane-error'
            });
            $('#modalProgressGlobal').modal('hide');
        })
        // get image information
/*        $.ajax({
            url: hosturl + '/imagecloud/service/image/' + imageId,
            type: 'get',
            data: {},

            dataType: 'json',
            success: function (data) {

                var message = parseMessageData(data.message);
                imageInfo = message;

                iWindowVNum = 1;
                iWindowHNum = 1;
                loadStudy(hosturl, patId, studyUID, dcmurl, serverURL);
                window.addEventListener('resize', resizeCanvas, false);
                if (imageType == 'jpg') {
                    $('#getDicom').find('span').html('DCM');
                } else {
                    $('#getDicom').find('span').html('JPG');
                }
            },
            error: function (data) {
                humane.log("影像服务器连接错误，请联系客服。", {
                    timeout: 4000,
                    clickToClose: true,
                    addnCls: 'humane-error'
                });

                $('#modalProgressGlobal').modal('hide');
            }
        });*/

    },function(data){
        humane.log("影像服务器连接错误，请联系客服。", {
            timeout: 4000,
            clickToClose: true,
            addnCls: 'humane-error'
        });
        $('#modalProgressGlobal').modal('hide');
    });



    
    
    // $.ajax({
    //     url: hosturl + '/imagecloud/service/ImageViewer/getConfig',
    //     type: 'get',
    //     data: {},
    //
    //     dataType: 'json',
    //     success: function (data) {
    //
    //         var urls = data.message.split(";");
    //
    //         // load image
    //         dcmurl = urls[0];
    //         serverURL = urls[1];
    //         queryString = window.location.href;
    //         patId = getParameter(queryString, "patientID");
    //         studyUID = getParameter(queryString, "studyUID");
    //         imageType = getParameter(queryString, "type");
    //         reportFlag = getParameter(queryString, "reportFlag");
    //         image2askid = getParameter(queryString, "image2askid" );
    //         isSReport = getParameter(queryString, "sReport" );
    //
    //         //zssure,at LinkingMed 2016-07-07
    //         if(patId == null||patId=="" || studyUID==null ||studyUID==""||imageType==null ||imageType=="")
    //         {
    //             patId = (patId == null||patId=="")?getParameter(queryString, "patientID"):patId;
    //             studyUID = (studyUID==null ||studyUID=="")?window.localStorage.getItem('studyUID'):studyUID;
    //             imageType = (imageType==null ||imageType=="")?getParameter(queryString, "type"):imageType;
    //         }
    //         //zssure,at LinkingMed 2016-07-07 end
    //         // get the dicom tags
    //         loadTagInfos(hosturl, studyUID);
    //
    //         // 判断是否显示相关的Tab
    //         if (null == image2askid || '' == image2askid || 'null' == image2askid) {
    //             //表示是阅片的状态
    //             $("#liTabReport").css("display", "none");
    //             $("#liTabInfo").css("display", "none");
    //             $("#liTabSReport").css("display", "none");
    //         }
    //         else {
    //             //表示是咨询的状态
    //             $("#liTabStartConsult").css("display", "none");
    //         }
    //         // if(askid){
    //         //
    //         // }
    //         // askId = window.localStorage.getItem('askid');
    //         // imageId = window.localStorage.getItem('imageid');
    //         askId = getParameter(queryString, "askid" );
    //         imageId = getParameter(queryString, "imageid" );
    //
    //         totalSeries = 0;
    //         if (isDesktop === true) {
    //             $('#enableScrollStack').css('display', 'none');
    //         }
    //         cancelBindKey();
    //         loadButtonHint();
    //         getStudyNumber();
    //
    //         // get image information
    //         $.ajax({
    //             url: hosturl + '/imagecloud/service/image/' + imageId,
    //             type: 'get',
    //             data: {},
    //
    //             dataType: 'json',
    //             success: function (data) {
    //
    //                 var message = parseMessageData(data.message);
    //                 imageInfo = message;
    //
    //                 iWindowVNum = 1;
    //                 iWindowHNum = 1;
    //                 loadStudy(hosturl, patId, studyUID, dcmurl, serverURL);
    //                 window.addEventListener('resize', resizeCanvas, false);
    //                 if (imageType == 'jpg') {
    //                     $('#getDicom').find('span').html('DCM');
    //                 } else {
    //                     $('#getDicom').find('span').html('JPG');
    //                 }
    //             },
    //             error: function (data) {
    //                 humane.log("影像服务器连接错误，请联系客服。", {
    //                     timeout: 4000,
    //                     clickToClose: true,
    //                     addnCls: 'humane-error'
    //                 });
    //
    //                 $('#modalProgressGlobal').modal('hide');
    //             }
    //         });
    //
    //     },
    //     error: function (data) {
    //         humane.log("影像服务器连接错误，请联系客服。", {
    //             timeout: 4000,
    //             clickToClose: true,
    //             addnCls: 'humane-error'
    //         });
    //
    //         $('#modalProgressGlobal').modal('hide');
    //     }
    // });
});

//获得检查数量
function getStudyNumber() {

    if (askId == null) {
        return;
    }

    var data = {};
    data.askid = askId;
    data.curpage = 1;
    data.pagesize = 5;

    lmViewer.srv.service_ask_imagelist(data,function(data){
        console.log("[tabViewer|service_ask_imagelist|success]---"+JSON.stringify(data,null,4));
        var result = data.result;
        if (result == 0) {
            var message = data.message;
            if (message) {
                studyNumber = message.length;
            }
        } else if (result == -1) {
            humane.log("获取影像数据失败");
        } else {
            humane.log("未知错误");
        }
    },function(data){
        humane.log("服务器异常");
    });

  /*  $.ajax({
        url: hosturl+'/imagecloud/service/ask/imagelist',
        type: 'get',
        data: data,
        dataType: 'json',
        success: function (data) {
            var result = data.result;
            if (result == 0) {
                var message = parseMessageData(data.message);
                if (message) {
                    studyNumber = message.length;
                }
            } else if (result == -1) {
                humane.log("获取影像数据失败");
            } else {
                humane.log("未知错误");
            }
        },
        error: function (data) {
            humane.log("服务器异常");
        }
    });*/
}

//序列对象排序
function sortTagSeries() {
    var tempTagArray = [];
    var sNum = series.length;

    // 将tagArray与seriesArray的序列顺序统一,之前seriesArray曾用此法与series统一过
    for (var i = 0; i < sNum; i++) {
        for (var j = 0; j < sNum; j++) {
            if (series[i].seriesIUID == seriesArray[j].seriesUID) {
                tempTagArray.push(tagArray[j]);
                break;
            }
        }
    }
    tagArray = tempTagArray;

    //将tagArray与seriesArray每个序列的instance顺序统一
    for (var i = 0; i < sNum; i++) {
        var tempInstances = [];
        var iNum = seriesArray[i].instance.length;

        for (var se = 0; se < iNum; se++) {
            for (var tag = 0; tag < iNum; tag++) {
                if (seriesArray[i].instance[se].sopIUID == tagArray[i][tag].instanceId) {
                    tempInstances.push(tagArray[i][tag]);
                    break;
                }
            }
        }
        tagArray[i] = tempInstances;
    }
}

// The following is for the report
function searchType() {
    var treeNodez = $("#treeNodez");
    if ('' != treeNodez.html()) {
        return;
    }
    var t = '';



    $.ajax({
            url: "/imagecloud/service/imgReportTemplate/get",
            type: 'POST',
            success: function (data) {
                data = JSON.parse(JSON.parse(data));
                var result = data.result;

                if (result == 0) {
                    var message = JSON.parse(data.message);
                    for (var i = 0; i < message.length; i++) {

                        t += '<li data-id="'
                            + (i + 1)
                            + '"><div style="cursor:pointer;background-color:#FFFFFF" id = "'
                            + message[i].type
                            + '" onclick="searchDetailType(\''
                            + message[i].parentId + '\',\''
                            + message[i].type
                            + '\');"><font color="#000000">+'
                            + message[i].type + '</font></div></li>';
                    }
                    treeNodez.html(t);
                    treeNodez.hide();
                    treeNodez.slideDown();
                }
            },
            error: function (data) {
                humane.log("服务器异常", {
                    timeout: 4000,
                    clickToClose: true,
                    addnCls: 'humane-error'
                });
            }
        });
    searchLevelhfour('', '');
}

function searchDetailType(parentIds, types) {
    var typeObj = $("#" + types);
    var parentId = parentIds;
    var type = types;
    var t = '';
    var newData = {
        "parentId": parentId,
        "type": type
    }
    $.ajax({
            url: "/imagecloud/service/imgReportTemplate/levelOne",
            type: 'POST',
            data: newData,

            success: function (data) {
                data = JSON.parse(JSON.parse(data));
                var result = data.result;

                if (result == 0) {
                    var message = JSON.parse(data.message);
                    for (var i = 0; i < message.length; i++) {
                        // t += '<option value=' + message[i].templateUID +
                        // '>'
                        // + message[i].templateName + '</option>';
                        if ("Y" == message[i].isHasChild) {
                            t += '<li ><div style="cursor:pointer;background-color:#FFFFFF" id="'
                                + message[i].templateUID
                                + '" onclick="searchLevelone(\''
                                + message[i].templateUID
                                + '\',\''
                                + message[i].templateName
                                + '\');" ><font color="#000000">+'
                                + message[i].templateName
                                + '</font></div></li>';
                        } else {
                            t += '<li ><div style="cursor:pointer;background-color:#FFFFFF" id="'
                                + message[i].templateUID
                                + '" onclick="searchLevelhfour(\''
                                + message[i].templateUID
                                + '\',\''
                                + message[i].templateName
                                + '\');" ><font color="#000000">'
                                + message[i].templateName
                                + '</font></div></li>';
                        }

                    }
                    t = '<div style="cursor:pointer;background-color:#FFFFFF" onclick="showDetailType(\''
                        + parentId
                        + '\',\''
                        + type
                        + '\');" id="'
                        + type
                        + '"><font color="#000000">-'
                        + type
                        + '</font></div><ol>' + t + '</ol>';
                    var b2 = $("#" + type).parent(); // 父节点；
                    b2.html(t);
                    b2.hide();
                    b2.slideDown();
                }
            },
            error: function (data) {
                // alert("服务器异常");
                humane.log("服务器异常", {
                    timeout: 4000,
                    clickToClose: true,
                    addnCls: 'humane-error'
                });
            }
        });
    searchLevelhfour('', '');
}
function showDetailType(parentId, type) {

    var b2 = $("#" + type).parent();
    b2.slideUp();
    var t = '<div style="cursor:pointer;background-color:#FFFFFF" onclick="searchDetailType(\''
        + parentId
        + '\',\''
        + type
        + '\');" id="'
        + type
        + '"><font color="#000000">+' + type + '</font></div>';
    b2.html(t);
    b2.slideDown();
    searchLevelhfour('', '');
}

// ------Updated by TanQilu (uncompleted...)
function achieveInstanceInfo() {
    var loc = [];
    var thick = [];
    var orient = [];
    var pos = [];

    var imageIDs = [];
    for (var i = 0; i < seriesArray.length; i++) {
        loadImages(hosturl, serverURL, studyUID, seriesArray[i], imageIDs, imageType);
        for (var j = 0; j < seriesArray[i].instance.length; j++) {

            //		console.log('Test');
            //		!function(j){
            cornerstone.loadAndCacheImage(imageIDs[j]).then(function (image) {
                console.log('Test');
                loc[j] = image.data.floatString('x00201041');
                thick[j] = image.data.floatString('x00180050');
                orient[j] = image.data.floatString('x00200037', 0).toString() + '/' +
                    image.data.floatString('x00200037', 1).toString() + '/' +
                    image.data.floatString('x00200037', 2).toString() + '/' +
                    image.data.floatString('x00200037', 3).toString() + '/' +
                    image.data.floatString('x00200037', 4).toString() + '/' +
                    image.data.floatString('x00200037', 5).toString();
                pos[j] = image.data.floatString('x00200032', 0).toString() + '/' +
                    image.data.floatString('x00200032', 1).toString() + '/' +
                    image.data.floatString('x00200032', 1).toString();

            });//}(j);
            //   		loc[j] = seriesArray[i].instance[j].sliceLocation;
            //   		thick[j] = seriesArray[i].instance[j].sliceThickness;
            //   		orient[j] = seriesArray[i].instance[j].orientation;
            //   		pos[j] = seriesArray[i].instance[j].imgPosition;
        }
        locations.push(loc);
        thickness.push(thick);
        orientation.push(orient);
        position.push(pos);
        loc = [];
        thick = [];
        orient = [];
        pos = [];

        imageIDs = [];
    }
}


// doctor not found for image tag
function doctorNotfound() {
    var img = event.srcElement;
    img.src = "../img/avatar.png";
    img.onerror = null; //  控制不要一直跳动
}

function notifyConfigure() {
    humane.timeout = 4000;
    humane.addnCls = 'humane-info';
}

//resize the canvas to fit the image
function resizeCanvas() {
    $('#content').css('marginTop',($('.navbar-static-top').height() + $('#tabs1').height() + $('.nav-tabs').height()).toString() + 'px');//设置影像框距离距离顶部距离
    if (series[0].modality != "CT") {
        $('#toolBar').css('display', 'none');
    }
    $('#slice-range').css('display', 'none');
    var seriesDivHeight = $('#content').height();
    var clientWidth = document.body.clientWidth;
    var clientHeight = document.body.clientHeight;

    if (clientWidth > clientHeight) {
        $('#vertical').css('display', 'block');
        $('#transverse').css('display', 'none');
        $(' #contentDiv').parent().css('position', 'absolute');
        $(' #contentDiv').parent().css('left', '');
        var width = (document.body.clientWidth - $('#series').width() - $('.sidebar-collapse').width()).toString() + 'px';
        $(' #contentDiv').parent().css('width', width.toString());
    } else {
        $('#vertical').css('display', 'none');
        $('#transverse').css('display', 'block');
        $('#contentDiv').parent().css('position', "");
        var width = (document.body.clientWidth - $('#series').width() - $('.sidebar-collapse').width()).toString() + 'px';
        $(' #contentDiv').parent().css('width', width.toString());
    }

    var cnt = parseInt('0');

    if (clientWidth > clientHeight) {
        document.getElementById("imageContainer").style.width =
            (document.body.clientWidth - $('#series').width() - $('.sidebar-collapse').width()).toString() + 'px';
        // console.log(document.getElementById("imageContainer").style.width);
    } else {
        document.getElementById("imageContainer").style.width =
            document.body.clientWidth.toString() + 'px';
        // console.log(document.getElementById("imageContainer").style.width);
    }
    /**
     * 用于当左侧框收缩或展开时控制右侧影像向左或向右移动，但宽度没有调整；
     *
     */
    $('#content').css('left','150px');
    if ($('#side-menu').attr('style') && windowWidth == document.body.clientWidth && windowHeight == document.body.clientHeight){
        if (clientWidth > clientHeight) {
            document.getElementById("imageContainer").style.width =
                (document.body.clientWidth - $('#series').width() - $('.sidebar-collapse').width() - 150).toString() + 'px';
        }
    }

    /**
     * 计算“影像”，“数量”的高度
     */
    $('#series').css('height',(document.body.clientHeight - $('.navbar-static-top').height() - $('#tabs1').height() - $('.nav-tabs').height()).toString() + 'px');
    $('#content').css('height',(document.body.clientHeight - $('.navbar-static-top').height() - $('#tabs1').height() - $('.nav-tabs').height()).toString() + 'px');

    for (var x = 0; x < iWindowHNum; x++) {
        for (var y = 0; y < iWindowVNum; y++) {

            var imageDivId = "image" + x.toString() + y.toString();
            var element = $('#' + imageDivId).get(0);

            if (element === undefined) {
                continue;
            }

            var enabledElement = cornerstone.getEnabledElement(element);
            var currCanvas = enabledElement.canvas.getContext('2d').canvas;
           // var totalWidth = $('#imageContainer').width();
            var totalWidth = document.body.clientWidth - $('#series').width() - $('.sidebar-collapse').width();
            /**
             * 用于当左侧框收缩或展开时，调整影像的宽度；
             * 刚进入页面时不计算；
             */
            if(isFirst){
                isFirst = false;
            }else{
                if ($('#side-menu').attr('style') && windowWidth == document.body.clientWidth && windowHeight == document.body.clientHeight){
                    if(!isGetDicomButtonPressed)
                        totalWidth = document.body.clientWidth - $('#series').width() - $('.sidebar-collapse').width() - 150;
                    else if(isGetDicomButtonPressed){
                        totalWidth = document.body.clientWidth - $('#series').width() - $('.sidebar-collapse').width();
                        isGetDicomButtonPressed = false;
                    }
                }else if( !$('#side-menu').attr('style') && windowWidth == document.body.clientWidth && windowHeight == document.body.clientHeight){
                    if(!isGetDicomButtonPressed)
                        totalWidth = document.body.clientWidth - $('#series').width() - $('.sidebar-collapse').width() + 150;
                    else if(isGetDicomButtonPressed){
                        totalWidth = document.body.clientWidth - $('#series').width() - $('.sidebar-collapse').width() - 150;
                        isGetDicomButtonPressed = false;
                    }/*else{
                        totalWidth = document.body.clientWidth - $('#series').width() - $('.sidebar-collapse').width() - 300;
                        document.getElementById("content").style.width =
                            (document.body.clientWidth - $('#series').width() - $('.sidebar-collapse').width() - 300).toString() + 'px';
                    }*/
                }else if(windowWidth != document.body.clientWidth || windowHeight != document.body.clientHeight){
                    $('#liViewer').css('marginLeft',(($('.tabs-container').width()-$('#toolbar-function').width())/2 + 15).toString() + 'px');//设置工具栏的位置
                    //窗体大小改变时设置宽度
                    windowWidth = document.body.clientWidth;
                    windowHeight == document.body.clientHeight;
                    totalWidth = document.body.clientWidth - $('#series').width() - $('.sidebar-collapse').width() - 300;
                }
            }

            var totalHeight = document.body.clientHeight - $('.navbar-static-top').height() - $('#tabs1').height() - $('.nav-tabs').height() - 5 * iWindowHNum - 2 * iWindowHNum - 5;
            if (isMobile) {
                if (clientWidth > clientHeight) {
                    //横屏
                    $(' #contentDiv').parent().css('left', '150px');
                    document.getElementById("imageContainer").style.width =
                        (document.body.clientWidth - $('#series').width()).toString() + 'px';
                    var width = ($(' #imageContainer').width()).toString() + 'px';
                    $(' #toolBar').css('width', width);
                    if (isMobile) {
                        $(' #toolBar').css('width', '');
                        $(' #toolBar').css('margin-left', ' 100%');
                    }
                    totalHeight = document.body.clientHeight - $('#app-nav').height() - $('#tabs1').height() - 19;
                } else {
                    //竖屏
                    $(' #contentDiv').parent().css('left', '');
                    $(' #contentDiv').parent().css('width', '');
                    document.getElementById("imageContainer").style.width =
                        document.body.clientWidth.toString() + 'px';
                    var width = ($(' #imageContainer').width()).toString() + 'px';
                    $(' #toolBar').css('width', width);
                    if (isMobile) {
                        $(' #toolBar').css('width', '');
                        $(' #toolBar').css('margin-left', ' 85%');
                    }
                    totalHeight = document.body.clientHeight - $('#app-nav').height() - $('#tabs1').height() - $('#transverse').height() - 4;
                }
            }
            currCanvas.width = Math.floor(totalWidth / iWindowVNum);
            currCanvas.height = Math.floor(totalHeight / iWindowHNum);
            var iWidth = Math.floor(totalWidth / iWindowVNum);
            var iHeight = Math.floor(totalHeight / iWindowHNum);

            currCanvas.style.width = iWidth.toString() + 'px';
            currCanvas.style.height = iHeight.toString() + 'px';
            cornerstone.fitToWindow(element);
            if (isDesktop && imageType == "dicom") {
                plottingScale(element);
            }

            // PC浏览器为竖屏时样式调整
            if (isDesktop && clientWidth < clientHeight) {
                var contentHeight = window.innerHeight - $('#navbar').height() - $('#tabs1').height() - 15;
                var imageContainerHeight = contentHeight - $('#series_transverse').height() - 10;
                $(' #contentDiv').parent().css('width', '100%');
                $(' #contentDiv').parent().css('height', contentHeight.toString());

                $(' #imageContainer').css('width', '100%');
                $(' #imageContainer').css('height', imageContainerHeight.toString());

                $(' #' + imageDivId).parent().css('width', '100%');
                $(' #' + imageDivId).parent().css('height', (imageContainerHeight / iWindowHNum - 2 * iWindowHNum).toString());

                $(' #' + imageDivId).find('canvas')[0].width = ($(' #imageContainer').width() - 4) / iWindowVNum;
                $(' #' + imageDivId).find('canvas')[0].height = imageContainerHeight / iWindowHNum - 4 * iWindowHNum - 4;
                $(' #' + imageDivId).find('canvas')[0].style.width = (($(' #imageContainer').width() - 4) / iWindowVNum) + 'px';
                $(' #' + imageDivId).find('canvas')[0].style.height = (imageContainerHeight / iWindowHNum - 4 * iWindowHNum - 4) + 'px';

                $(' #series_transverse').css('width', $(' #imageContainer').width().toString());

                // 刷新影像
                cornerstone.updateImage($('#' + imageDivId).get(0));
            }

            cnt++;
        }
    }
}

/**
 * 阅片按钮归类，按归类显示
 */
//移动分类按钮
$("#move").click(function () {
    $("#pan").fadeToggle("quick");
    $("#RotateRight").fadeToggle("quick");
    $("#RotateLeft").fadeToggle("quick");
    $("#vFlip").fadeToggle("quick");
    $("#hFlip").fadeToggle("quick");
    $("#cornerMark").fadeToggle("quick");
    $("#getDicom").fadeToggle("quick");


});
//浏览分类按钮
$("#scan").click(function () {
    $("#enableLength").fadeToggle("quick");
    $("#probe").fadeToggle("quick");
    $("#circleroi").fadeToggle("quick");
    $("#rectangleroi").fadeToggle("quick");
    $("#angle").fadeToggle("quick");
    $("#ShowAnnotation").fadeToggle("quick");
    $("#UnShowAnnotation").fadeToggle("quick");


});
$("#other").click(function () {
    $("#invert").fadeToggle("quick");
    $("#wwwc").fadeToggle("quick");
    $("#synchronizer").fadeToggle("quick");
    $("#referenceLine").fadeToggle("quick");
    $("#threeViews").fadeToggle("quick");
    $("#saveImg").fadeToggle("quick");
    $("#reset").fadeToggle("quick");

});

$("#liTabInfo").click(function () {
    $("#toolbar-function").css("display", "none");
});
$("#liTabReport").click(function () {
    $("#toolbar-function").css("display", "none");
});
$("#liTabSReport").click(function () {
    $("#toolbar-function").css("display", "none");
});
$("#liTabImage").click(function () {
    $("#toolbar-function").css("display", "block");
});
